package chartor;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.Timer;
import java.util.TimerTask;

public class JUJI extends Gun{
	private Timer timer=new Timer();
	private TimerTask task;
	public JUJI(Rectangle p) {
		super(35, 100, p,10,10,50,"狙击枪");
		this.setMaxnumber(10);
		this.setNumber(this.getMaxnumber());
		task=new TimerTask() {
			@Override
			public void run() {
				setCool(true);
			}
		};
		timer.scheduleAtFixedRate(task, 0, 1000);
	}
    public void tututu(int state,Point target) {
    	if(this.getNumber()<=0||!this.getCool())
    		return;
    	Point t;
    	switch (state) {
		case 1:
			t=new Point(target.x, target.y);
			Plas.bullets.add(new Bullet(new Point(this.getManRectangle().x, this.getManRectangle().y), t, this.getManRectangle(), super.getW(),super.getH(),super.getDamage(),super.getSpeed()));
			break;
		case 2:
			t=new Point(target.x-40+Plas.random.nextInt(80), target.y-40+Plas.random.nextInt(80));
			Plas.bullets.add(new Bullet(new Point(this.getManRectangle().x, this.getManRectangle().y), t, this.getManRectangle(), this.getW(),this.getH(),this.getDamage(),this.getSpeed()));
			break;
		case 3:
			t=new Point(target.x-60+Plas.random.nextInt(120), target.y-60+Plas.random.nextInt(120));
			Plas.bullets.add(new Bullet(new Point(this.getManRectangle().x, this.getManRectangle().y), t, this.getManRectangle(), this.getW(),this.getH(),this.getDamage(),this.getSpeed()));
			break;
		default:
			break;
		}
    	this.setNumber(this.getNumber()-1);
    	setCool(false);
    }
	@Override
	public void load() {
		// TODO Auto-generated method stub
		setNumber(getMaxnumber());
	}
}
